package com.sdh.onlinemarket.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.sdh.onlinemarket.common.annotation.AdminToken;
import com.sdh.onlinemarket.common.lang.Result;
import com.sdh.onlinemarket.entity.Sells;
import com.sdh.onlinemarket.service.SellsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.time.LocalDate;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 施德昊
 * @since 2022-02-23
 */
@Api(tags = "销量统计")
@RestController
@RequestMapping("/sells")
public class SellsController {
    @Autowired
    SellsService sellsService;

    @AdminToken
    @ApiOperation(value = "获取商品销量")
    @GetMapping("/getitemsell")
    @ResponseBody
    public Result getItemSell(String itemid){
        if(itemid == null){
            return Result.fail("参数错误");
        }else if (sellsService.list(new QueryWrapper<Sells>().eq("itemid",itemid))==null){
            return Result.fail("未找到商品对应销量");
        }
        return Result.succ("成功获取商品销量",sellsService.list(new QueryWrapper<Sells>().eq("itemid",itemid)));
    }

    @AdminToken
    @ApiOperation(value = "获取某日销量",notes = "传入日期格式如：2022-01-28")
    @GetMapping("/getonedaysell")
    @ResponseBody
    public Result getOneDaySell(String date){
        if(date == null){
            return Result.fail("参数错误");
        }else if (sellsService.list(new QueryWrapper<Sells>().eq("selldate",date))==null){
            return Result.succ("未找到日期对应销量",null);
        }
        return Result.succ("成功获取该日销量",sellsService.list(new QueryWrapper<Sells>().eq("selldate",date)));
    }


}
